﻿using mozhi.smarterp.BasicData.Enums;
using System;
using Volo.Abp;

namespace mozhi.smarterp.BasicData.PaymentTerms
{
    public class PaymentTerm : AggregateRootBase
    {
        public PaymentTermBasisType BasisType { get; private set; }

        public int Days { get; private set; }

        public PaymentTermType Type { get; private set; }

        private PaymentTerm() { }

        public PaymentTerm(Guid id, string code, string name, bool activated, PaymentTermBasisType basisType, int days, PaymentTermType type) : base(id, code, name, activated)
        {
            Id = id;
            BasisType = basisType;
            Days = days;
            Type = type;

            Validate();
           
        }

        public void Change(string code, string name, bool activated, PaymentTermBasisType basisType, int days)
        {
            base.Change(code, name, activated);

            BasisType = basisType;
            Days = days;

            Validate();
        }


        #region
        protected override void Validate()
        {
            base.Validate();

            Check.NotDefaultOrNull<PaymentTermBasisType>(BasisType, nameof(BasisType));

            if (Days < 0)
                throw new UserFriendlyException("天数不能小于0", "100000");

            Check.NotDefaultOrNull<PaymentTermType>(Type, nameof(Type));
        }
        #endregion
    }
}
